﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcCms.Data;

namespace System
{
    public static class TicketExtension
    {
        public static string GetTicketChanges(this Ticket ticket, List<object[]> changes)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table>");
            sb.Append("<tr><th>Field</th><th>Old Value</th><th>New Value</th></tr>");

            foreach (object[] change in changes)
            {
                object propertyName = change[0] ?? "";
                object originalPropertyValue = change[1] ?? "";
                object newPropertyValue = change[2] ?? "";

                if (originalPropertyValue.ToString() != newPropertyValue.ToString())
                {
                    sb.Append("<tr>");
                    sb.Append(string.Format("<td>{0}</td>", propertyName));
                    sb.Append(string.Format("<td>{0}</td>", originalPropertyValue));
                    sb.Append(string.Format("<td>{0}</td>", newPropertyValue));
                    sb.Append("</tr>");
                }
            }
            sb.Append("</table>");
            return sb.ToString();
        }
    }
}
